var layer;
var form;
var laySP;
$(function(){
	// 显示头像
	$("#index_img").attr("src",$projectPath+loginImg+"?v="+Math.random());
	layui.use(['layer','form','upload'], function() {
		layer = layui.layer;
		form = layui.form;
		if(!sp){
			suoping();
		}
		// 提交锁屏
		form.on('submit(subSp)',function(data){
			subSP(1);
			return false;
		})
	});
	
	// 删除选中操作
	$('.layui-layout-right dd').click(function(){
		$(this).removeClass('layui-this');
	})
	
	// 全屏/退出全屏
	$('.screen').click(function(){
		var id = $(this).attr('lay-id');
		if(id == 0){
			fullScreen();
			$(this).attr({'lay-id': "1", "title": "退出全屏"});
			$(this).find(".layui-icon").html('&#xe758;');
		}else{
			 exitFullscreen();
			$(this).attr({'lay-id': "0", "title": "全屏"});
			$(this).find(".layui-icon").html('&#xe622;');
		}
	})
	// 锁屏
	$('#lockScreen').click(function(){
		suoping();
		subSP();
	})
	//setInterval("getSysDate()",1000);
})

/**
 * 加载中的线条-加载完成----------------------------------------------
 */
function closeLoadLine(){
	clearInterval(loadCountInter);
	$(".load_line_blue").css('width','100%');
	setTimeout(function(){
		$(".load_line_blue").remove();
	}, 500)
}
var loadCountInter;
/**
 * 加载中的线条------------------------------------------------------
 */
function loadLine(){
	$("body").append('<div class="load_line_blue"></div>');
	var loadCountLine = 0;
	loadCountInter = setInterval(function(){
		loadCountLine = loadCountLine + 10;
		if(loadCountLine <= 80 ){
			$(".load_line_blue").css('width',loadCountLine+'%');
		}
	},10)
}
//loadLine();

window.onload=function(){ 
//	closeLoadLine();
	// 加载中换成转圈圈
	setTimeout(function(){
		$(".lay-loader").fadeOut();
	}, 1000)
}

/**
 * 基本信息----------------------------------------------------------
 */
function basic(){
	layer.msg("待开发",{offset: "20%"});
}

/**
 * 锁屏-------------------------------------------------------------
 */
function suoping() {
	$('#suoping').val('');
	laySP = layer.open({
		title : '请输入登录密码解锁',
		type : 1,
		shade : 0.2,
		//skin : 'layui-layer-molv',// 样式类名
		closeBtn : 0,
		area : ['360px','110px'],
		btn : false,
		resize : false, // 禁止拉伸
		content : $('#div_sp'),
		time : 0,
		success : function(){
			layer.msg("锁屏中",{offset: "20%"});
		}
	});
}

/**
 * 锁屏校验----------------------------------------------------------
 */
function subSP(mark) {
	var obj = {};
	if(mark){
		var val = $('#suoping').val();
		if(!val){
			return layer.msg("请输入密码",{offset:"20%"});
		}
		obj = {'suoping': aesMinEncrypt(val), 'mark': 1}
	}
	$.post($projectPath+'/main/suoping', obj, function(res) {
		if (res.success) {
			sp = res.data;
			layer.close(laySP);
		}
		if(!res.msg){
			return layer.msg("您尚未登录，请刷新页面",{offset:"20%"});
		}
		layer.msg(res.msg,{offset:"25%"});
	})
}

/**
 * 退出登录---------------------------------------------------------
 */
function exitLogin(){
	window.location.href = "loginExit";
}

/**
 * 清除缓存----------------------------------------------------------
 */
function clearCache() {
	$.post($projectPath+'/main/clearCache', {}, function(res) {
		if(!res.msg){
			return layer.msg("您尚未登录，请刷新页面",{offset:"25%"});
		}
		layer.msg(res.msg,{offset:"25%"});
	})
}

/**
 * 大数据界面---------------------------------------------------------
 */
function showData() {
	window.open($projectPath+'/views/data/sysData?oid='+oid);
}

/**
 * 全屏--------------------------------------------------------------
 */
function fullScreen() {
    var element = document.documentElement;
    if (element.requestFullscreen) {
        element.requestFullscreen();
    } else if (element.msRequestFullscreen) {
        element.msRequestFullscreen();
    } else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    } else if (element.webkitRequestFullscreen) {
        element.webkitRequestFullscreen();
    }
}

/**
 * 退出全屏-----------------------------------------------------------
 */
function exitFullscreen() {
    if (document.exitFullscreen) {
        document.exitFullscreen();
    } else if (document.msExitFullscreen) {
        document.msExitFullscreen();
    } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
    }
}
//监听window是否全屏，并进行相应的操作,支持esc键退出
window.onresize = function() {
    var isFull=!!(document.webkitIsFullScreen || document.mozFullScreen || 
        document.msFullscreenElement || document.fullscreenElement
    );//!document.webkitIsFullScreen都为true。因此用!!
    if (isFull==false) {
		$(".screen").attr({'lay-id': "0", "title": "全屏"});
		$(".screen i").html('&#xe622;');
	}else{
		$(".screen").attr({'lay-id': "1", "title": "退出全屏"});
		$(".screen i").html('&#xe758;');
	}
}






